﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using OVS.CoreDomain;
using OVS.CoreDomain.Business;
using OVS.CoreDomain.Data;
using OVS.Data;
using OVS.Common;

namespace OVS.Business
{
    public class BusinessEncryptVotes : IBusinessEncryptVotes
    {

        #region IBusinessEncryptVotes Members

        public void DecryptVotes(List<ICandidate> candidates)
        {
            foreach (ICandidate candidate in candidates)
            {
                DecryptVote(candidate);
            }
           
        }

        public void EncryptVotes(List<ICandidate> candidates)
        {
            foreach (ICandidate candidate in candidates)
            {
                EncryptVote(candidate);     
            }
            
        }

        public void DecryptVote(ICandidate candidate)  
        {
            if (candidate.VotesEncrypted == null)
                candidate.Votes = 0;
            else
            {
                string _decrypted = RijndaelSimple.Decrypt(candidate.VotesEncrypted.ToString());
                candidate.Votes = Int64.Parse(_decrypted);
            }
                
           
        }

        public void EncryptVote(ICandidate candidate)
        {

            candidate.VotesEncrypted = RijndaelSimple.Encrypt(candidate.Votes.ToString());
           
        }


        #endregion
    }
}
